package com.mjh.config;

import java.util.ArrayList;
import java.util.HashMap;
import com.mjh.bean.Category;
import com.mjh.bean.SystemConfig;
import com.mjh.manager.CategoryConfigManager;
import com.mjh.manager.SystemConfigManager;

public class GlobalConfig {

	private static HashMap<String,String> CATEGORY_MAP = new HashMap<String,String>();
	
	private static SystemConfig SYS_CONFIG;
	
	static {
		GlobalConfig.setCategoryMap(new CategoryConfigManager().listCategory());
		GlobalConfig.setSysConfig(new SystemConfigManager().getSysConfig());
	}
	
	private static void putCategory2Map(Category c){
		CATEGORY_MAP.put(c.getId(), c.getName());
		for(Category ca : c.getSubCategory()){
			putCategory2Map(ca);
		}
	}
	
	public static void setCategoryMap(ArrayList<Category> allCategory){
		CATEGORY_MAP.clear();
		for(Category c : allCategory){
			putCategory2Map(c);
		}
	}
	
	public static String getCategoryName(String id){
		return CATEGORY_MAP.get(id);
	}
	
	public static void setSysConfig(SystemConfig s){
		SYS_CONFIG = s;
	}
	
	public static SystemConfig getSysConfig(){
		return SYS_CONFIG;
	}
}
